<?php
namespace app\controller;

use think\Request;
use think\facade\Db;
use think\facade\Cache;

class Logout extends Common
{
	/**
	 * 退出接口
	 *
	 * @return
	 */
	public function index(Request $request)
	{
		$token = $request->param('token', '', 'trim');
		if(!$token) {
			return json(['msg' => '退出成功!', 'code' => 0]);
		}
		$token = substr($token, 7);
		$cache = Cache::get($token);
		if(isset($cache['id'])) {
			$this->cfg_write_logs($request, $token, $cache['companyId'], $cache['nickname'], $cache['username'], 2);
			Cache::delete($token);
		}
		return json(['msg' => '退出成功!', 'code' => 0]);
	}

}
